/*
 * @LastEditTime: 2023-02-28 14:38:06
 */
import { router } from "../index";
import { LeaderBoard } from "../../Models/LeaderBoard.schema";
import { LeaderBoardController } from "../../Controller/LeaderBoard.controller"
import { createLeaderBoardDTO, updateLeaderBoardDTO } from "../../DTO/LeaderBoard.dto";

const LeaderBoardModel = new LeaderBoardController(LeaderBoard);

// router.prefix("/api/leaderBoard");

//按id获取排行榜
router.get("/leaderBoard/List", async (ctx, next) => {
  ctx.body = await LeaderBoardModel.getLederBoard();
})
//获取全部排行榜
// router.get("/leaderBoard/:all", async (ctx, next) => {
//   ctx.body = await LeaderBoardModel.findAll();
// });
// 创建排行榜
router.post('/leaderBoard', async (ctx, next) => {
  console.log(1);
  ctx.body = await LeaderBoardModel.createItem(ctx.request.body as createLeaderBoardDTO);
});
//删除排行榜
router.delete("/leaderBoard/:id", async (ctx, next) => {
  ctx.body = await LeaderBoardModel.removeById(ctx.params.id);
});

// 更新排行榜
router.patch("/leaderBoard/:id", async (ctx, next) => {
  if (ctx.params.id)
    ctx.body = await LeaderBoardModel.updateById(
      ctx.params.id,
      ctx.request.body as updateLeaderBoardDTO
    );
});